package com.xx.xiawan.net;

import android.util.Log;

import com.android.volley.http.StringEntity;
import com.dg.acb.utils.LogUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

/**
 * Created by Administrator on 2017-09-01.
 */

public class JsonStringEntity extends StringEntity {

    protected byte[] encodeParameters(Map<String, String> params, String paramsEncoding) {
        JSONObject jsonObject = new JSONObject();
        try {
            for (Map.Entry<String, String> entry : params.entrySet()) {
                if (LogUtil.DEBUG) {
                    LogUtil.d("post:" + entry.getKey() + "=>" + entry.getValue());
                }
                try {
                    jsonObject.put(entry.getKey(),entry.getValue());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            Log.e("login","jsonObject is "+jsonObject.toString());
            return jsonObject.toString().getBytes(paramsEncoding);
        } catch (UnsupportedEncodingException uee) {
            throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee);
        }
    }
}
